package com.lanou3g.zjl.chating.dao;

import android.content.Context;

import com.lanou3g.zjl.chating.dao.greendao.RecommendEntity;
import com.lanou3g.zjl.chating.dao.greendao.RecommendEntityDao;

import java.util.List;

/**
 * Created by dllo on 15/11/17.
 */
public class RecommendEntityDaoHelper {
    //定义数据库表的单例
    private DaoSingleton daoSingleton;
    //定义表的操作类
    private RecommendEntityDao entityDao;

    //构造函数初始化单例对象和操作类对象
    public RecommendEntityDaoHelper(Context context){

        daoSingleton = DaoSingleton.getInstance(context);

        entityDao = daoSingleton.getRecommendDao();
    }

    /**
     *
     * 添加方法,直接添加一个实体类对象
     * */
    public void insertData(RecommendEntity recommendEntity){

        entityDao.insert(recommendEntity);
    }
    /**
     *
     * 添加方法,添加一个以实体类对象为元素的集合
     * */
    public void insertData(List<RecommendEntity> recommendEntityList){

        entityDao.insertInTx(recommendEntityList);

    }
    /**
     *
     * 添加方法(写入或者替换),添加一个以实体类对象为元素的集合
     * */
    public void inserOrReplacetData(List<RecommendEntity> recommendEntityList){

        entityDao.insertOrReplaceInTx(recommendEntityList);

    }
    /**
     *
     * 删除方法,根据id删除数据
     * */
    public void deleteDataById(Long id){

        entityDao.deleteByKey(id);
    }
    /*
    * 删除方法,清空所有数据
    * **/
    public void deleteAll(){

        entityDao.deleteAll();
    }
    /**
     *
     * 修改方法,参数为实体类对象
     * */
    public void updateData(RecommendEntity recommendEntity){

        entityDao.update(recommendEntity);
    }
    /**
     *
     * 查询方法,参数为实体类对象
     * */
    public List<RecommendEntity> selecteData(){

        return entityDao.queryBuilder().list();
    }
}
